<template>
	<div class="category-content">
		<div class="main-width">
			<div class="promotions-item" v-for="item in active">
				<router-link tag="div" :to="{name: 'MarketingDetail', query:{id: item.activityId, contentId: item.contentMarketingId, brand: item.brandNameCn}}">
					<div class="promotions-item-image">
						<img :src="imgAddress + item.titlePicture" @error="error(3)">
					</div>
				</router-link>
					<div class="promotions-item-content">
						<router-link tag="div" :to="{name: 'MarketingDetail', query:{id: item.activityId, contentId: item.contentMarketingId, brand: item.brandNameCn}}">
							<div class="marketing-item-title">{{item.title}}</div>
							<div class="promotions-item-richTxt">{{item.content}}</div>
						</router-link>
						<div class="font-right promotions-update-time">发布方：{{item.brandNameCn}} 时间：{{item.updateTime}} 
							<a :href="item.richTxtPath" class="marketing-download"></a>
						</div>
					</div>
			</div>
			<div class="block">
				<el-pagination layout="prev, pager, next" @current-change="handleCurrentChange" :current-page.sync="condition.pageNum" :total="total" :page-size="30"></el-pagination>
			</div>
		</div>
	</div>
</template>
<script>
	import {toast, imageError} from '../util/tool.js'
	import {getMarketingList, imgAddress} from '../config/interface.js'
	import store from '../store/index.js'
	import {fetch} from '../config/fetch.js'

	export default{
		data(){
			return {
				imgAddress: imgAddress,
				condition: {
					userId: store.state.userId,
					pageNum: 1,
					pageSize: 10
				},
				active: [],
				total: 0
			}
		},
		mounted(){
			this.init();
		},
		methods: {
			error(num){
				imageError(num, event);
			},
			init(){
				const data = this.condition;
				const url = getMarketingList;

				fetch(url, data)
				.then(res => {
					this.active = res.data.list;
					this.total = res.data.count;
					for(var i = 0; i < this.active.length; i++){
						this.active[i].updateTime = this.active[i].updateTime.substring(0,19);
					}
				})
			},
			handleCurrentChange(val){
		        this.condition.pageNum = val;
		        this.init();
		    }
		}
	}
</script>